#===============================================================================
# Koro Business Environment
# Copyright (C) 2008  Antonio Corroppoli
#
#This file is part of Koro BE.
# 
# Koro BE is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# Koro BE is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with Koro BE; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#===============================================================================
print 'importo gEvents'
# eventType #
#####I CODICI DEVONO CORRISPONDERE ALLA TAVOLA DELLE TABELLE DEFINITA IN gDbFunction
#####todo: evitare di scrivere il codice(definire costanti)
####gEVT_CLIENTI = 0
####gEVT_AZIENDE = 1
####gEVT_RUBRICA = 2
####gEVT_AGENDA = 3
####gEVT_BANCHE = 4
####gEVT_CATEG = 5

gEVT_LOGIN = 0
##cambiare le costanti gEVT_* (sostituire il numero dalla stringa nome_tabella:
from gap.gConstants import *
gEVT_CLIENTI = T_ANACLI
gEVT_AZIENDE = T_ANAZ
gEVT_RUBRICA = T_RUBRICA
gEVT_AGENDA = T_AGENDA
gEVT_BANCHE = T_BANCHE
gEVT_CATEG = T_CATEG
gEVT_PRODOTTI = T_PRODOTTI
gEVT_LISTINI  = T_LISTINI

#actions
gGET_ALL = 100
gGET_FROM_KEY = 101
gSAVE = 102
gGET_ALL_DICT = 103
gDEL = 104
gLOGIN = 105
gEXIT = 106
gNEWTAB=107
gDELTAB=108


class gEventBase(object):
    def __init__(self,eventType,value=None):
        self._eventType = eventType
        self._value     = value
    def __str__(self):
        return repr(self._value)
    def _getValue(self):
        return self._value
    def _getEventType(self):
        return self._eventType
    def _getId(self):##non so;forse futuro
        return -1

    key=property(_getValue)
    data=property(_getValue)
    eventType=property(_getEventType)
    scrId = property(_getId)


    
    

class gActionEvent(gEventBase):
    """Action request."""
    def __init__(self,eventType,value=None,action=gGET_FROM_KEY):
        """Create an ActionEvent.

        eventType -- gEVT_CLIENTI
                     gEVT_AZIENDE
                     gEVT_RUBRICA 
                     gEVT_AGENDA
                     gEVT_BANCHE
                     gEVT_CATEG
                     gEVT_LISTINI
        value     -- tipically the key of record
        action    -- gGET_ALL
                     gGET_FROM_KEY (default)
                     gSAVE
                     gLOGIN
                     gEXIT.
        """
        gEventBase.__init__(self,eventType,value)
        self.__action=action

    def getAction(self):
        return self.__action
    

class gEventClienti(gEventBase):
    """deprecated. Lasciata per compatibilita'.
    Eliminare dopo aver eliminato le dipendenze"""
    eventType = gEVT_CLIENTI
    def __init__(self,value=None):
        gEventBase.__init__(self,gEVT_CLIENTI,value)
        
    def _getValue(self):
        return self._value
    key=property(_getValue)

class gLoginEvent(gActionEvent):
    """classe Evento Login."""
    def __init__(self,value=None,action=gLOGIN):
        gActionEvent.__init__(self,gEVT_LOGIN,value,action)
    

class gClientiEvent(gActionEvent):
    """Nuova classe Eventi Clienti. Da sistemare!!!"""
    def __init__(self,value=None,action=gGET_FROM_KEY):
        gActionEvent.__init__(self,gEVT_CLIENTI,value,action)   
    

class gCategEvent(gActionEvent):
    def __init__(self,value=None,action=gGET_FROM_KEY):
        gActionEvent.__init__(self,gEVT_CATEG,value,action)


class gBancEvent(gActionEvent):
    def __init__(self,value=None,action=gGET_FROM_KEY):
        gActionEvent.__init__(self,gEVT_BANCHE,value,action)
        
class gAziendeEvent(gActionEvent):
    def __init__(self,value=None,action=gGET_FROM_KEY):
        gActionEvent.__init__(self,gEVT_AZIENDE,value,action)

class gProdEvent(gActionEvent):
    def __init__(self,value=None,action=gGET_FROM_KEY):
        gActionEvent.__init__(self,gEVT_PRODOTTI,value,action)

